package com.hx.springboot1.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author: hx
 * Date: 2021-05-12 22/20
 * Description: Nothing else
 */
@Slf4j
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        //  实现  登出成功的方法
        String username = ((User) authentication.getPrincipal()).getUsername();
        log.info("注销成功...用户名：{}", username);//  自动把 数据库的  rememberMe的 表格数据  删除了？？
        // 重定向
        httpServletResponse.sendRedirect("/loginPage");
    }
}
